var openDialog;
function OnBegin(xhr) {
    $("#res-status").show();
}

function ajaxSubmit() {
    var action = $('#ajaxform').attr('action');
    if (action) {
        $url = action;
    } else {
        layer.msg('请输入跳转地址');
        return false;
    }
    $.post($url, $('#ajaxform').serialize(), function (data) {
        Onsuccess(data);
    })
}
function Onsuccess(data) {
    if (data.code) {
        layer.msg(data.msg);
        setTimeout(function () {
            layer.closeAll();
            var index = layer.load('正在跳转...');
            window.location.href = data.url
        }, 2000);
    } else {
        layer.msg(data.msg);
    }
}

$(function () {
    $("#vform").bind('valid.form', function () {
        var self = $(this);
        $.ajax({
            url: self.attr("action"),
            type: self.attr("method"),
            data: self.serialize(),
            beforeSend: OnBegin,
            success: Onsuccess
        });
    });
});

function targetBlank(url) {
    var a = document.createElement('a');
    var id = 'tiao';
    a.setAttribute('href', url);
    a.setAttribute('target', '_blank');
    a.setAttribute('id', id);
    // 防止反复添加
    if (!document.getElementById(id)) {
        document.body.appendChild(a);
    }
    a.click();
}
